--[[
	删除邮件
]]
local filename = "delmail.lua"

local timetool = require "timetool"
local skynet = require "skynet"
local cluster = require "skynet.cluster"
local filelog =require "filelog"

local json = require "cjson"
json.encode_sparse_array(true,1,1)


local service = nil
local CMD = {
	service = nil
}

-- socket传来的请求，可以获取邮件列表
function CMD.process(rid, msgbody)
	if not service then
		service = CMD.service
	end
	local keyid = tostring(msgbody.keyid)
	local result = cluster.call("datanode", ".router", "delete_rk", rid, "rm_mail", keyid)
	if result[1] == 1 then -- 只有真正删除成功，才去加钻石
        --保存附件邮件日志 操作名 操作id rid keyid 附件json编码
        local logstr = string.format("%s,%d,%d,%d,%d,%s","del_mail", 2, rid, keyid, 0, nil)
        skynet.send(".maillog", "lua", "write", logstr)
		return {retcode=0, retstr="del mail ok"}
	else
		return {retcode=-7, retstr="del mail error. NOT add diamond"}
	end
end

return CMD
